package com.xuetang9.t9.hotel.controller;

import com.xuetang9.t9.hotel.beans.Arranging;
import com.xuetang9.t9.hotel.services.IArrangingService;
import com.xuetang9.t9.hotel.services.ITableTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 排号controller
 */
@Controller
@RequestMapping("/arranging")
@ResponseBody
public class ArrangingController {
    @Autowired
    private IArrangingService arrangingService;

    /**
     * 保存排号接口
     * @param arranging
     * @return
     */
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    private Map save(@RequestBody Arranging arranging){
        Map map = new HashMap<Integer,String>();
        if(arranging == null){
            map.put(201,"无效参数");
            return map;
        }
        arranging.setState("等待");
        if(arrangingService.save(arranging) > 0){
            map.put(200,"操作成功");
           return map;
        }else{
            map.put(500,"操作失败");
        }
        return map;
    }
    /**
     * 获取当前排号记录
     * @param
     * @return
     */
    @RequestMapping(value = "/show",method = RequestMethod.POST)
    private List showByAll(){
        return arrangingService.selectByTodayAll();
    }

    /**
     * 修改排号数据之后返回新的数据
     * @param arranging
     * @return
     */
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    private List update(@RequestBody Arranging arranging){
        arrangingService.update(arranging);
        return arrangingService.selectByTodayAll();
    }

    /**
     * 删除排号
     * @param
     * @return
     */
    @RequestMapping(value = "/remove/{id}",method = RequestMethod.POST)
    private List update(@PathVariable("id") Integer id){
        arrangingService.remove(id);
        return arrangingService.selectByTodayAll();
    }



}
